package com.wljy.developtool.config.cp;

import me.chanjar.weixin.cp.bean.message.*;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportRuntimeHints;

import java.util.stream.Stream;

@Configuration(proxyBeanMethods = false)
@ImportRuntimeHints(WxCpNativeConfiguration.MyBaitsRuntimeHintsRegistrar.class)
public class WxCpNativeConfiguration {

    static class MyBaitsRuntimeHintsRegistrar implements RuntimeHintsRegistrar {

        @Override
        public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
            Stream.of(
                    WxCpMessageSendResult.class,
                    WxCpTpXmlMessage.class,
                    WxCpLinkedCorpMessageSendResult.class,
                    WxCpSchoolContactMessage.class,
                    WxCpXmlApprovalInfo.class,
                    WxCpSchoolContactMessageSendResult.class,
                    WxCpXmlOutNewsMessage.class,
                    WxCpXmlOutUpdateBtnMessage.class,
                    WxCpXmlOutTaskCardMessage.class,
                    WxCpAppChatMessage.class,
                    WxCpXmlOutMessage.class,
                    WxCpMessageSendStatistics.class,
                    WxCpXmlMessage.class,
                    WxCpLinkedCorpMessage.class,
                    WxCpXmlOutEventMessage.class,
                    WxCpXmlOutImageMessage.class,
                    WxCpXmlOutTextMessage.class,
                    WxCpMessage.class,
                    WxCpGroupRobotMessage.class,
                    WxCpXmlOutVideoMessage.class,
                    WxCpXmlOutVoiceMessage.class,
                    WxCpMessageSendResult.class
            ).forEach(x -> hints.reflection().registerType(x, MemberCategory.values()));
            Stream.of(
                    "org/apache/ibatis/builder/xml/*.dtd",
                    "org/apache/ibatis/builder/xml/*.xsd"
            ).forEach(hints.resources()::registerPattern);
        }
    }

}
